var mongoose = require('mongoose')
,   config   = require('./config')
,   model    = require('./model');

module.exports = function(next){
    var that    = this;


    mongoose.connect(config.uri,{useMongoClient : true});

    var db = mongoose.connection;

        db.once('connected', function(){

            that.model  = model.call(that);

            that.status = true;
            if(next)
                next();
        });

        db.once('error', function(){
            that.status = false;
            if(next)
                next();
        });
};